angular.module('SmartCanteenApp.report', ['ngRoute', 'ngTouch'])

	.config(['$routeProvider', function($routeProvider) {
		$routeProvider.when('/canteenCash', {  // 食堂终端收银日报
			templateUrl: 'reports/canteenCashierReport.html',
			controller: 'canteenCashierReportCtrl'
		});
		$routeProvider.when('/othersCash', {
			templateUrl: 'reports/othersCashierReport.html',
			controller: 'othersCashierReportCtrl'
		});
		$routeProvider.when('/summaryReport', {
			templateUrl: 'reports/summaryReport.html',
			controller: 'summaryReportCtrl'
		});
		$routeProvider.when('/itemsSalesReport', {
			templateUrl: 'reports/itemsSalesReport.html',
			controller: 'itemsSalesReportCtrl'
		});
		$routeProvider.when('/itemPriceAnalysis', {
			templateUrl: 'reports/itemPriceAnalysis.html',
			controller: 'itemPriceAnalysisCtrl'
		});
		$routeProvider.when('/productSales', {
			templateUrl: 'reports/productSales.html',
			controller: 'productSalesCtrl'
		});
		$routeProvider.when('/cardConsumption', {
			templateUrl: 'reports/cardConsumption.html',
			controller: 'cardConsumptionCtrl'
		});
		$routeProvider.when('/cardMessage', {
			templateUrl: 'reports/cardMessage.html',
			controller: 'cardMessageCtrl'
		});
		$routeProvider.when('/transactionItemSaleStatistic', {
			templateUrl: 'reports/itemSalesNew.html',
			controller: 'itemSalesNewCtrl'
		});
		$routeProvider.when('/transactionWindowDailyReport', {
			templateUrl: 'reports/windowSales.html',
			controller: 'windowSalesCtrl'
		});
		$routeProvider.when('/transactionDailyReport', {
			templateUrl: 'reports/dailyReport.html',
			controller: 'dailyReportCtrl'
		});
	}])
	//餐卡信息列表
	.controller('cardMessageCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$scope.pagination([])
		$(".select2").select2()
		//获取卡类型
		$scope.getCardTypeNames = function(){
			$scope.getJson($scope.resultPath+'/wisdomeatery/v1/base_system/canteens/'+$scope.canteenId+'/sales_mode/cardTypes','','get',function(data){
    			console.log(data)
    			$scope.cards = data.data
  			})
		}
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		   	//获取基础数据
			$scope.getCardTypeNames();
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
			$scope.getCardTypeNames();
		});
		//查询对象
		$scope.searchCardMessageData = {
			"cardType":"",
			"status":"",
			"user":""
		}
		//发送查询条件
		$scope.searchCardMessage = function(){
			console.log($scope.searchCardMessageData)
			var path1 = $scope.resultPath+"/wisdomeatery/v1/canteens/"+$scope.canteenId+"/reports/85dea963254e423698099ertyq45632a?value=card_type_name="+$scope.searchCardMessageData.cardType+"@card_status="+$scope.searchCardMessageData.status+"@params="+$scope.searchCardMessageData.user
			$scope.getJson(path1,'','get',function(data){
				console.log(data)
				if(data.code == 0){
					$scope.theader = data.data.table_header
					$scope.tbody = data.data.table_body
					$scope.pagination($scope.tbody)
				}else{
					$scope.showError(data.msg)
				}
			})
		}
	}])
	//食堂终端收银日报
	.controller('canteenCashierReportCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$('#datepicker').datepicker({
		      autoclose: true
		});
		$(".select2").select2();
		//请求所有终端操作员 id name
		//请求所有餐别
	}])
	//其他终端消费统计
	.controller('othersCashierReportCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$('#reservation').daterangepicker();
		$(".select2").select2();
		//获取当前年月日yyyy-mm-dd
		$scope.getNowFormatDate = function() {
				    var date = new Date();
				    var seperator1 = "-";
				    var seperator2 = ":";
				    var month = date.getMonth() + 1;
				    var strDate = date.getDate();
				    if (month >= 1 && month <= 9) {
				        month = "0" + month;
				    }
				    if (strDate >= 0 && strDate <= 9) {
				        strDate = "0" + strDate;
				    }
				    var now = date.getFullYear() + seperator1 + month + seperator1 + strDate;
				    
				    return now;
		}
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate()
	}])
	//终端消费汇总
	.controller('summaryReportCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$scope.pagination([])
		$(".select2").select2();
		$('#reservation').daterangepicker();
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate()
		//获取所有食堂用户
		$scope.UsersInC = function(){
			$scope.getJson($scope.resultPath+'/wisdomeatery/v1/menus/canteens/'+$scope.canteenId+'/chief','','get',function(data){
				console.log(data)
				if(data.code == 0){
					$scope.usersInC = data.data
				}else{
					$scope.showError('获取菜品分类失败')
					console.log(data)
				}
			})
		}
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		   	//获取基础数据
			$scope.UsersInC();
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
			$scope.UsersInC();
		});
		//定义查询对象
		$scope.searchSummaryData = {
			"user":"",
			"start_time":"",
			"end_time":""
		}
		$scope.searchSummary = function(){
			var arr = $scope.searchDate.split(" 至 ")
			$scope.searchSummaryData.start_time = arr[0]
			$scope.searchSummaryData.end_time = arr[1]
			console.log($scope.searchSummaryData)
			var url =  $scope.resultPath+"/wisdomeatery/v1/canteens/"+$scope.canteenId+"/reports/8654bdrety23351450954125wet9541a?value=date_begin="+$scope.searchSummaryData.start_time+"@date_end="+$scope.searchSummaryData.end_time+"@opt_user="+$scope.searchSummaryData.user
			$scope.getJson(url,'','get',function(data){
				console.log(data)				
				console.log(url)
				if(data.code == 0){
					$scope.summaryTB = data.data.table_body
					$scope.summaryTH = data.data.table_header
					$scope.pagination($scope.summaryTB)
				}else{
					$scope.showError(data.msg)
				}
			})
		}
	}])
	//菜品销售统计
	.controller('itemsSalesReportCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$('#reservation').daterangepicker();
		$(".select2").select2();
		$scope.pagination([])
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate()
		$scope.getC = function(){
			$scope.getJson($scope.resultPath+'/wisdomeatery/v1/menus/canteens/'+$scope.canteenId+'/categorys','','get',function(data){
				console.log(data)
				if(data.code == 0){
					$scope.categorys = data.data
				}else{
					$scope.showError('获取菜品分类失败')
					console.log(data)
				}
			})
		}
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		   	//获取基础数据
			$scope.getC();
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
			$scope.getC();
		});
		//发送查询 取回报表
		$scope.searchItemSale = {
			"start_time":"",
			"end_time":"",
			"category":"",
			"name":""
		}
		$scope.searchItemSaleReport = function(){
			var arr = $scope.searchDate.split(" 至 ")
			$scope.searchItemSale.start_time = arr[0]
			$scope.searchItemSale.end_time = arr[1]
			console.log($scope.searchItemSale)
			var url = $scope.resultPath+'/wisdomeatery/v1/canteens/'+$scope.canteenId+'/reports/9d78b56747b2435e90974cd84a5817de?'
			var url1 = 'value=start_date='+$scope.searchItemSale.start_time+'@end_date='+$scope.searchItemSale.end_time+'@category_name='+$scope.searchItemSale.category+'@item_name='+$scope.searchItemSale.name
			$scope.getJson(url+url1,'','get',function(data){
				console.log(data)
				console.log(url+url1)
				if(data.code == 0){
					$scope.theader = data.data.table_header
					$scope.tbody = data.data.table_body
					$scope.pagination($scope.tbody)
				}else{
					$scope.showError(data.msg)
				}
			})
			
		}
	}])
	//餐卡消费报表
	.controller('cardConsumptionCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$scope.searchByUser = ''
		$('#reservation').daterangepicker();
		$(".select2").select2();
		$scope.pagination([])
		var allDataStatic = undefined
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate()
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
		});
		$scope.searchCardConsumption = function(){
			var arr = $scope.searchDate.split(" 至 ")
			var start_time = arr[0]
			var end_time = arr[1]
			var url =  $scope.resultPath+'/wisdomeatery/v1/canteens/'+$scope.canteenId+'/reports/759651db9034b5a9645177b522563da?value=create_time_begin='+start_time+'@create_time_end='+end_time+'@card_user='+$scope.searchByUser+'@canteen_id='+$scope.canteenId
			console.log(url)
			$scope.getJson(url,'','get',function(data){
				console.log(data)				
				console.log(url)
				if(data.code == 0){
					$scope.cardConsumptionTB = data.data.table_body
					$scope.cardConsumptionTH = data.data.table_header
					$scope.pagination($scope.cardConsumptionTB)
				}else{
					$scope.showError(data.msg)
				}
			})
		}
	}])
	//菜品价格分析
	.controller('itemPriceAnalysisCtrl', ['$scope', '$timeout', function($scope, $timeout) {
//		$('#reservation').daterangepicker();
		$(".select2").select2();
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate()
	}])
	//菜品生产、销售对比
	.controller('productSalesCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$('#startDate').datepicker({
		  autoclose: true
		});
		$('#endDate').datepicker({
		  autoclose: true
		});
		$scope.getNowFormatDate = function() {
				    var date = new Date();
				    var seperator1 = "-";
				    var seperator2 = ":";
				    var month = date.getMonth() + 1;
				    var strDate = date.getDate();
				    if (month >= 1 && month <= 9) {
				        month = "0" + month;
				    }
				    if (strDate >= 0 && strDate <= 9) {
				        strDate = "0" + strDate;
				    }
				    var now = date.getFullYear() + seperator1 + month + seperator1 + strDate;
				    
				    return now;
		}
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate()
	}])
	//财大上线前新增报表 产品销售
	.controller('itemSalesNewCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$('#reservation').daterangepicker();
		//分页-------------------------------------
		    //每页展示数改变时调取此方法
			$scope.change = function( items ){
				console.log(items);
				$scope.pageSize = items ;//改变后的每页显示数
				$scope.pages = Math.ceil($scope.itemSalesNewdata.length / $scope.pageSize); //分页数
				$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
				$scope.pageList = [];
				$scope.selPage = 1;
				$scope.itemSalesNew = $scope.itemSalesNewdata.slice(0, $scope.pageSize);
				//分页要repeat的数组
				for (var i = 0; i < $scope.newPages; i++) {
					$scope.pageList.push(i + 1);
				}
				//设置表格数据源(分页)
				$scope.setitemSalesNewData = function () {
					$scope.items = $scope.itemSalesNewdata.slice(($scope.pageSize * ($scope.selPage - 1)), ($scope.selPage * $scope.pageSize));//通过当前页数筛选出表格当前显示数据
				}
			}
			//设置表格数据源(分页)
			$scope.setitemSalesNewData = function () {
				if($scope.itemSalesNewdata == [] || $scope.itemSalesNewdata ==undefined || $scope.itemSalesNewdata =='undefined'){
					return;
				}
				$scope.itemSalesNew = $scope.itemSalesNewdata.slice(($scope.pageSize * ($scope.selPage - 1)), ($scope.selPage * $scope.pageSize));
			}
			//打印当前选中页索引
			$scope.selectPage = function (page) {
				//不能小于1大于最大
				if (page < 1 || page > $scope.pages) return;
				//最多显示分页数5
				if (page > 2) {
				//因为只显示5个页数，大于2页开始分页转换
				var newpageList = [];
				for (var i = (page - 3) ; i < ((page + 2) > $scope.pages ? $scope.pages : (page + 2)) ; i++) {
				newpageList.push(i + 1);
				}
				$scope.pageList = newpageList;
				}
				$scope.selPage = page;
				$scope.setitemSalesNewData();
				$scope.isActivePage(page);
				console.log("选择的页：" + page);
			};
			//设置当前选中页样式
			$scope.isActivePage = function (page) {
				return $scope.selPage == page;
			};
			//上一页
			$scope.Previous = function () {
				$scope.selectPage($scope.selPage - 1);
			}
			//下一页
			$scope.Next = function () {
				$scope.selectPage($scope.selPage + 1);
			};
			//初始条码
			$scope.pageList = [1];
			//初始每页查询数量
			$scope.initial = 10;
            //表格分页数据处理
            $scope.pagination = function(datas){
//              	console.log(datas);
            	$scope.itemSalesNewdata = datas;
				//总条目数
				if(datas != null){
					$scope.totalNums = 	$scope.itemSalesNewdata.length ;
					//分页总数
					$scope.pageSize = 10;
					$scope.pages = Math.ceil($scope.itemSalesNewdata.length / $scope.pageSize); //分页数
					$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
					$scope.pageList = [];
					$scope.selPage = 1;
					$scope.itemSalesNew = $scope.itemSalesNewdata.slice(0, $scope.pageSize);
//						console.log($scope.items);
					//分页要repeat的数组
					for (var i = 0; i < $scope.newPages; i++) {
						$scope.pageList.push(i + 1);
					}
				}
            }
		//-----------------------------------------
		$(".select2").select2();
		$scope.pagination([])
//		
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate()
		$scope.getWindows = function(){
			
			$scope.getJson($scope.resultPath+'/wisdomeatery/v1/base_system/canteens/'+$scope.canteenId+'/windows','','get',function(data){
				console.log(data)
				if(data.code == 0){
					$scope.windows = data.data
					$scope.searchItemSaleReport()
				}else{
					$scope.showError('获取档口失败')
					console.log(data)
				}
			})
		}
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		   	//获取基础数据
			$scope.getWindows();
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
			$scope.getWindows();
		});
		//发送查询 取回报表
		$scope.searchItemSale = {
			"start_time":"",
			"end_time":"",
			"window_id":"",
		}
		$scope.searchItemSaleReport = function(){
			var arr = $scope.searchDate.split(" 至 ")
			$scope.searchItemSale.start_time = arr[0]
			$scope.searchItemSale.end_time = arr[1]
			console.log($scope.searchDate)
//			if($scope.searchItemSale.window_id == ''){
//				$scope.searchItemSale.window_id = null
//			}
			var url = $scope.resultPath+'/wisdomeatery/v1/canteens/'+$scope.canteenId+'/reports/BDDA57AFFF2AC49D1EF1FABFBF99BE73?'
			var url1 = 'value=start_date='+$scope.searchItemSale.start_time+'@end_date='+$scope.searchItemSale.end_time+'@window_id='+$scope.searchItemSale.window_id+'@canteen_id='+$scope.canteenId
			//var url = 'http://192.168.1.118:8080/wisdomeatery/v1/canteens/asdfgc22584e46d2aa4da940bbfghjkl/reports/BDDA57AFFF2AC49D1EF1FABFBF99BE73?value=start_date=2017-08-29@end_date=2017-08-29@window_id=c1c886f481f14a95ad372f9a161aadfa@canteen_id=asdfgc22584e46d2aa4da940bbfghjkl'
			$scope.getJson(url+url1,'','get',function(data){
				console.log(data)
				if(data.code == 0){
					$scope.createrItem = data.data.creater
					$scope.create_timeItem = data.data.create_time
					$scope.table_nameItem = data.data.table_name
					$scope.theaderItem = data.data.table_header
					$scope.realtbodyItem = data.data.table_body.concat()
					$scope.tbodyItem = data.data.table_body
					$scope.tfootItem = data.data.table_body.pop()
					console.log($scope.realtbodyItem)
					$scope.pagination($scope.tbodyItem)
				}else{
					$scope.showError(data.msg)
				}
			})
			
		}
	}])	
	//同上 档口销售报表
	.controller('windowSalesCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		//Date picker
	    $('#datepicker').datepicker({
	      autoclose: true
	    });
		$(".select2").select2();
		//分页-------------------------------------
		    //每页展示数改变时调取此方法
			$scope.change = function( items ){
				console.log(items);
				$scope.pageSize = items ;//改变后的每页显示数
				$scope.pages = Math.ceil($scope.windowSalesdata.length / $scope.pageSize); //分页数
				$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
				$scope.pageList = [];
				$scope.selPage = 1;
				$scope.windowSales = $scope.windowSalesdata.slice(0, $scope.pageSize);
				//分页要repeat的数组
				for (var i = 0; i < $scope.newPages; i++) {
					$scope.pageList.push(i + 1);
				}
				//设置表格数据源(分页)
				$scope.setwindowSalesData = function () {
					$scope.items = $scope.windowSalesdata.slice(($scope.pageSize * ($scope.selPage - 1)), ($scope.selPage * $scope.pageSize));//通过当前页数筛选出表格当前显示数据
				}
			}
			//设置表格数据源(分页)
			$scope.setwindowSalesData = function () {
				if($scope.windowSalesdata == [] || $scope.windowSalesdata ==undefined || $scope.windowSalesdata =='undefined'){
					return;
				}
				$scope.windowSales = $scope.windowSalesdata.slice(($scope.pageSize * ($scope.selPage - 1)), ($scope.selPage * $scope.pageSize));
			}
			//打印当前选中页索引
			$scope.selectPage = function (page) {
				//不能小于1大于最大
				if (page < 1 || page > $scope.pages) return;
				//最多显示分页数5
				if (page > 2) {
				//因为只显示5个页数，大于2页开始分页转换
				var newpageList = [];
				for (var i = (page - 3) ; i < ((page + 2) > $scope.pages ? $scope.pages : (page + 2)) ; i++) {
				newpageList.push(i + 1);
				}
				$scope.pageList = newpageList;
				}
				$scope.selPage = page;
				$scope.setwindowSalesData();
				$scope.isActivePage(page);
				console.log("选择的页：" + page);
			};
			//设置当前选中页样式
			$scope.isActivePage = function (page) {
				return $scope.selPage == page;
			};
			//上一页
			$scope.Previous = function () {
				$scope.selectPage($scope.selPage - 1);
			}
			//下一页
			$scope.Next = function () {
				$scope.selectPage($scope.selPage + 1);
			};
			//初始条码
			$scope.pageList = [1];
			//初始每页查询数量
			$scope.initial = 10;
            //表格分页数据处理
            $scope.pagination = function(datas){
//              	console.log(datas);
            	$scope.windowSalesdata = datas;
				//总条目数
				if(datas != null){
					$scope.totalNums = 	$scope.windowSalesdata.length ;
					//分页总数
					$scope.pageSize = 10;
					$scope.pages = Math.ceil($scope.windowSalesdata.length / $scope.pageSize); //分页数
					$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
					$scope.pageList = [];
					$scope.selPage = 1;
					$scope.windowSales = $scope.windowSalesdata.slice(0, $scope.pageSize);
//						console.log($scope.items);
					//分页要repeat的数组
					for (var i = 0; i < $scope.newPages; i++) {
						$scope.pageList.push(i + 1);
					}
				}
            }
		//-----------------------------------------
		
		$scope.getWindows = function(){
			$scope.getJson($scope.resultPath+'/wisdomeatery/v1/base_system/canteens/'+$scope.canteenId+'/period_times','','get',function(data){
				console.log(data)
				if(data.code == 0){
					$scope.periods = data.data
					$scope.searchItemSaleReport()
				}else{
					$scope.showError('获取餐别失败')
					console.log(data)
				}
			})
		}
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		   	//获取基础数据
			$scope.getWindows();
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
			$scope.getWindows();
		});
		//发送查询 取回报表
		$scope.searchItemSale = {
			"start_time":$scope.getNowFormatDate(),
			"periods_id":"",
		}
		$scope.searchItemSaleReport = function(){
			
			console.log($scope.searchItemSale)
			if($scope.searchItemSale.periods_id ==  null){
				$scope.searchItemSale.periods_id = ''
			}
			var url = $scope.resultPath+'/wisdomeatery/v1/canteens/'+$scope.canteenId+'/reports/BC6646BDB15F02381850567EE1A6D520?'
			var url1 = 'value=start_date='+$scope.searchItemSale.start_time+'@canteen_id='+$scope.canteenId+'@period_time_id='+$scope.searchItemSale.periods_id
			//var url1 = 'value=start_date='+$scope.searchItemSale.start_time+'@window_id=@canteen_id=asdfgc22584e46d2aa4da940bbfghjkl'+'@period_time_id='+$scope.searchItemSale.periods_id
			$scope.getJson(url+url1,'','get',function(data){
				console.log(url+url1)
				console.log(data)
				if(data.code == 0){
					$scope.createrWindow = data.data.creater
					$scope.create_timeWindow = data.data.create_time
					$scope.table_nameWindow = data.data.table_name
					$scope.theaderWindow = data.data.table_header
					$scope.realtbodyWindow = data.data.table_body.concat()
					$scope.tbodyWindow = data.data.table_body
					$scope.tfootWindow = data.data.table_body.pop()
					console.log($scope.realtbodyWindow)
					$scope.pagination($scope.tbodyWindow)
				}else{
					$scope.showError(data.msg)
				}
			})
			
		}
	}])
	//同上 经营日报
	.controller('dailyReportCtrl', ['$scope', '$timeout', function($scope, $timeout) {
		$(".select2").select2();
			//分页-------------------------------------
		    //每页展示数改变时调取此方法
			$scope.change = function( items ){
				console.log(items);
				$scope.pageSize = items ;//改变后的每页显示数
				$scope.pages = Math.ceil($scope.dailyReportdata.length / $scope.pageSize); //分页数
				$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
				$scope.pageList = [];
				$scope.selPage = 1;
				$scope.dailyReport = $scope.dailyReportdata.slice(0, $scope.pageSize);
				//分页要repeat的数组
				for (var i = 0; i < $scope.newPages; i++) {
					$scope.pageList.push(i + 1);
				}
				//设置表格数据源(分页)
				$scope.setwindowSalesData = function () {
					$scope.dailyReport = $scope.dailyReportdata.slice(($scope.pageSize * ($scope.selPage - 1)), ($scope.selPage * $scope.pageSize));//通过当前页数筛选出表格当前显示数据
				}
			}
			//设置表格数据源(分页)
			$scope.setwindowSalesData = function () {
				if($scope.dailyReportdata == [] || $scope.dailyReportdata ==undefined || $scope.dailyReportdata =='undefined'){
					return;
				}
				$scope.dailyReport = $scope.dailyReportdata.slice(($scope.pageSize * ($scope.selPage - 1)), ($scope.selPage * $scope.pageSize));
			}
			//打印当前选中页索引
			$scope.selectPage = function (page) {
				//不能小于1大于最大
				if (page < 1 || page > $scope.pages) return;
				//最多显示分页数5
				if (page > 2) {
				//因为只显示5个页数，大于2页开始分页转换
				var newpageList = [];
				for (var i = (page - 3) ; i < ((page + 2) > $scope.pages ? $scope.pages : (page + 2)) ; i++) {
				newpageList.push(i + 1);
				}
				$scope.pageList = newpageList;
				}
				$scope.selPage = page;
				$scope.setwindowSalesData();
				$scope.isActivePage(page);
				console.log("选择的页：" + page);
			};
			//设置当前选中页样式
			$scope.isActivePage = function (page) {
				return $scope.selPage == page;
			};
			//上一页
			$scope.Previous = function () {
				$scope.selectPage($scope.selPage - 1);
			}
			//下一页
			$scope.Next = function () {
				$scope.selectPage($scope.selPage + 1);
			};
			//初始条码
			$scope.pageList = [1];
			//初始每页查询数量
			$scope.initial = 10;
            //表格分页数据处理
            $scope.pagination = function(datas){
//              	console.log(datas);
            	$scope.dailyReportdata = datas;
				//总条目数
				if(datas != null){
					$scope.totalNums = 	$scope.dailyReportdata.length ;
					//分页总数
					$scope.pageSize = 10;
					$scope.pages = Math.ceil($scope.dailyReportdata.length / $scope.pageSize); //分页数
					$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
					$scope.pageList = [];
					$scope.selPage = 1;
					$scope.dailyReport = $scope.dailyReportdata.slice(0, $scope.pageSize);
//						console.log($scope.items);
					//分页要repeat的数组
					for (var i = 0; i < $scope.newPages; i++) {
						$scope.pageList.push(i + 1);
					}
				}
            }
		//-----------------------------------------
		$scope.pagination([])
		
//		$scope.searchDate = $scope.getNowFormatDate()
		$scope.getWindows = function(){
			$scope.getJson($scope.resultPath+'/wisdomeatery/v1/base_system/canteens/'+$scope.canteenId+'/windows','','get',function(data){
				console.log(data)
				if(data.code == 0){
					$scope.windows = data.data
					$scope.searchItemSaleReport()
				}else{
					$scope.showError('获取档口失败')
					console.log(data)
				}
			})
		}
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		   	//获取基础数据
			$scope.getWindows();
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
			$scope.getWindows();
		});
		//发送查询 取回报表
		var date = new Date();
		$scope.searchItemSale = {
			"select_month":date,
			"window_id":"",
		}
		$scope.searchItemSaleReport = function(){
			if($scope.searchItemSale.select_month == null){
				$scope.showError('请选择时间')
				return
			}
			$scope.realSearchDate = $scope.getFormatMonth($scope.searchItemSale.select_month)
			if($scope.searchItemSale.window_id == null){
				$scope.searchItemSale.window_id = ''
			}
			
			var url = $scope.resultPath+'/wisdomeatery/v1/canteens/'+$scope.canteenId+'/reports/5462052E2E8C63C5AE7A45E224C1B3C0?'
			var url1 = 'value=canteen_id='+$scope.canteenId+'@window_id='+$scope.searchItemSale.window_id+'@select_month='+$scope.realSearchDate

			$scope.getJson(url+url1,'','get',function(data){
				console.log(data)
				console.log(url+url1)
				if(data.code == 0){
					$scope.createrDaily = data.data.creater
					$scope.create_timeDaily = data.data.create_time
					$scope.table_nameDaily = data.data.table_name
					$scope.theaderDaily = data.data.table_header
					$scope.realtbodyDaily = data.data.table_body.concat()
					$scope.tbodyDaily = data.data.table_body
					$scope.tfootDaily = data.data.table_body.pop()
					console.log($scope.realtbodyDaily)
					$scope.pagination($scope.tbodyDaily,'dailyReport')
				}else{
					$scope.showError(data.msg)
				}
			})
			
		}
	}])	
    